#include <queue>
class Solution {
public:
    int findKth(vector<int>& nums, int n, int k) {
        int res = 0;
        priority_queue<int> q;
        for (int i = 0; i < n; ++i) {
            q.push(nums[i]);
        } 
        while (!q.empty()) {
            if (k-- == 1) {
                res = q.top();
            }
            q.pop();
        }
        return res;
    }
};